package de.baumann.browser.fragments.explore

import android.text.Html
import android.view.View
import de.baumann.browser.R
import de.baumann.browser.activitys.explore.ActiveActivity
import de.baumann.browser.activitys.explore.DestroyRecordActivity
import de.baumann.browser.activitys.oc.ImportWalletActivity
import de.baumann.browser.base.BaseOdinFragment
import de.baumann.browser.iview.IExploreViews
import de.baumann.browser.present.explore.ExplorePresenters
import de.baumann.browser.utils.getIsLogin
import de.baumann.browser.utils.getMoneyAddress
import de.baumann.browser.views.dialog.CreateOrImportDialog
import de.baumann.browser.views.dialog.OcWalletAgreementDialog
import kotlinx.android.synthetic.main.fragment_explore_fragments.*
import kotlinx.android.synthetic.main.fragments_mine.*


class ExploreFragments : BaseOdinFragment<IExploreViews, ExplorePresenters>(), IExploreViews {
    companion object {
        val instance: ExploreFragments by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            ExploreFragments()
        }
    }

    override fun getLayout(): Int {
        return R.layout.fragment_explore_fragments
    }

    private var bindMoneyAddress: String? = ""
    override fun initView(view: View) {
//        bindMoneyAddress = getMoneyAddress()
        tvTime.setOnClickListener {
            ActiveActivity.startActiveActivity(mContext)
        }
        txtPower.setOnClickListener {
            DestroyRecordActivity.startDestroyRecordActivity(mContext)
        }

    }

    override fun onResume() {
        super.onResume()
        bindMoneyAddress = getMoneyAddress()
        if (bindMoneyAddress == "") {
            CreateOrImportDialog(mContext)
                    .setSelectListener {
                        when (it) {
                            0 -> {
                                ImportWalletActivity.startImportWalletActivity(mContext)
                                return@setSelectListener

                            }
                            1 -> {
                                OcWalletAgreementDialog(mContext).show()
                                return@setSelectListener
                            }

                        }
                    }.show()

        } else {
            getPresenter().getCountDown()
            getPresenter().getSumPower()
            if (!getIsLogin()) {
                getPresenter().login()
            }
        }

    }

    override fun initData() {

    }

    override fun createPresenter(): ExplorePresenters? {
        return ExplorePresenters()
    }

    override fun createView(): IExploreViews? {
        return this
    }


    override fun setMinePower(power: String) {
    }

    override fun setCountDown(time: String) {
//        tvTime.text = Html.fromHtml("激励倒计时:<font><big><big> ${time}</big></big></font> 天")

    }

    override fun setSurplusPoser(surplusPower: String) {
        sumPower.text = Html.fromHtml("$surplusPower <font><small><small>算力</small></small></font>")

    }

    override fun setPoserSum(power: Int) {
        txtPower.text = "销毁算力：${power}"
    }
}